package com.publishsystem.action;

import com.publishsystem.po.Customer;
import com.publishsystem.service.CustomerService;
import com.publishsystem.util.BaseServlet;
import com.publishsystem.util.page.ResultInfo;
import org.apache.log4j.Logger;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class HomePageAction extends BaseServlet {
    private static final Logger logger = Logger.getLogger(HomePageAction.class);
    CustomerService customerService = new CustomerService();

    /**
     * 首页
     *
     * @param request
     * @param response
     * @return
     * @throws ServletException
     * @throws IOException
     */
    public ResultInfo home(HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> data = new HashMap<>();
        List<Customer> custList = customerService.queryAllCust();
        data.put("custList", custList);
        if (request.getSession().getAttribute("admin") != null) {
            data.put("isLogin", true);
        }
        return ResultInfo.success(data);
    }

}
